import {fetch} from '@/utils/fetch'

export const login = async (code) => {
  let res = await fetch({
    query: `mutation {
      wxLogin(code: "${code}") {
        access_token
        expires_in
        user_id
        avatar
        nick_name
      }
    }`,
  })
  return res.data.wxLogin
}

export const updateUserInfo = async ({encryptedData, iv}) => {
  let res = await fetch({
    query: `mutation {
      wxUserInfo(encryptedData: "${encryptedData}", iv: "${iv}") {
        access_token
        expires_in
        user_id
        avatar
        nick_name
      }
    }`
  })
  return res.data.wxUserInfo
}
